/**
 * 
 */
package com.magnusart.scrumppm.gui;

import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Color;
import org.eclipse.swt.graphics.RGB;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.List;
import org.eclipse.swt.widgets.Text;

import com.magnusart.scrumppm.presenters.AbstractPresenter.WidgetTypes;

/**
 * Encompasses the GUI design for the Project panel
 * @author magnus
 *
 */
public class ProjectChooser extends Composite
{
	private Label projectLabel;
	private Label searchLabel;
	private Text search;
	private GridData data;
	private List projectList;
	private Button openProject;
	
	/**
	 * @param parent The parent of this panel.
	 */
	public ProjectChooser( Composite parent ) {
		super( parent, SWT.None );
		initialize();
	}

	private void initialize() {
		// Setup the layout
		setLayout( new GridLayout( 2, false ) );

		data = new GridData( GridData.BEGINNING | GridData.HORIZONTAL_ALIGN_FILL );
		data.horizontalSpan = 2;
		
		// Setup the label
		projectLabel = new Label( this, SWT.NONE );
		projectLabel.setText( "Projects" );
		projectLabel.setFont( FontFormatter.getBoldFont() );
		projectLabel.setLayoutData( data );
	
		data = new GridData( GridData.FILL | GridData.GRAB_HORIZONTAL );
		data.horizontalSpan = 2;
		
		Label info = new Label( this, SWT.NONE | SWT.WRAP );
		info.setText( "Please select a project from the list below" );
		info.setLayoutData( data );
		
		// Setup the search label
		searchLabel = new Label( this, SWT.NONE );
		searchLabel.setText( "Search" );
		
		data = new GridData( GridData.HORIZONTAL_ALIGN_FILL 
				| GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_BEGINNING );
		search = new Text( this, SWT.SEARCH | SWT.BORDER | SWT.FILL );
		search.setText( "Enter keyword..." );
		search.setData(  WidgetTypes.ProjectSearch );
		search.setForeground( new Color(Display.getCurrent(), new RGB(150, 150, 150 ) ) );
		search.setLayoutData( data );
		
		data = new GridData( GridData.HORIZONTAL_ALIGN_FILL
				| GridData.VERTICAL_ALIGN_FILL 
				| GridData.GRAB_HORIZONTAL 
				| GridData.GRAB_VERTICAL );
		data.horizontalSpan = 2;
		
		projectList = new List( this, SWT.SINGLE | SWT.BORDER | SWT.V_SCROLL );
		projectList.setItems( new String[] { "" } );
		projectList.setData( WidgetTypes.SelectProjectInList );
		projectList.setLayoutData( data );
		projectList.setFocus(); // This gives focus to the project selection list?
		
		data = new GridData( GridData.GRAB_HORIZONTAL | GridData.HORIZONTAL_ALIGN_BEGINNING );
		data.horizontalAlignment = GridData.END;
		data.horizontalSpan = 2;
		
		openProject = new Button( this, SWT.PUSH );
		openProject.setText( "Open project" );
		openProject.setData( WidgetTypes.OpenProjectButton );
		openProject.setLayoutData( data );
	}
	
	/**
	 * @return Reference to the display project button.
	 */
	public Button getOpenProject() {
		return openProject;
	}

	/**
	 * @return Reference to the project list.
	 */
	public List getProjectList() {
		return projectList;
	}

	
	/**
	 * @return Reference to the search text input.
	 */
	public Text getSearch() {
		return search;
	}
	
	
}
